<?php 
class Zend_Template_View {
    
    private $_controller;
    private $_actions;
    private $_smarty;
    
    public function __construct($controller, $actions){
        $this->_controller = $controller;
        $this->_actions = $actions;
        $this->_smarty = new Smarty();
        $this->_smarty->setTemplateDir(PATH_STRUCTURE."/zend-framework/templates/views");
    }   
    
    /**
     * Render form 
     * @author tien.nguyen
     * @return string
     */
    public function render($action){
        $this->_smarty->assign('action', $action);
        $template = $this->_smarty->fetch('show-all.tpl');
        return $template;
    }
    
    public function writeFile(){
        //create folder action
        $pathView = PATH_PROJECT_GENERAL.'/'.
            NAME_PROJECT_GENERAL.'/application/views/scripts/'.
            $this->_controller->controller_uri;
        if(!file_exists($pathView)){
            mkdir($pathView, 777);
        }
        //write file
        foreach($this->_actions as $action){
            $path = $pathView.'/'.$action->action_uri.'.phtml';    
            $hand = fopen($path, 'w');
            fwrite($hand, $this->render($action));
            fclose($hand);    
        }    
    }
    
    public function readTemplate($templateName){
        $template = file_get_contents(PATH_STRUCTURE.'/zend-framework/templates/views/'.$templateName.'.tpl');
        return $template;
    }
    
}